package mest.controller.Modeling;

import com.alibaba.fastjson.JSON;
import mest.VO.Modeling.WorkrouteWork_manytomany.workVO;
import mest.entity.work_route;
import mest.entity.workroutework_manytomany;
import mest.service.Modeling.IworkRouteService;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description
 * @auther Machenike
 * @create 2019-11-15 22:41
 */
@RestController
@CrossOrigin
@RequestMapping(value = "/workRouteFile")
public class workRouteFile {

    @Resource
    private IworkRouteService iwrs;

    @RequestMapping(value="/insert")
    public String insert(work_route wf ){

        int i = iwrs.insertWorkRouteType(wf);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }
    @RequestMapping(value = "/baseSelect", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String baseSelect(int index,int pageSize) {

        List<work_route> workRoutePage = iwrs.findWorkRoutePage(index, pageSize);
        int i = iwrs.selectCount();
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",workRoutePage);
        return JSON.toJSONString(map);
    }


    //    toolbar查看工序详情
    @RequestMapping(value="/WorkDetail", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String WorkDetail(int wrid,int index,int pageSize){

        System.out.println(wrid);
        List<workVO> workByWRId = iwrs.findWorkByWRId(wrid,index,pageSize);
        int i = iwrs.WorkCount(wrid);
        Map map  = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",i);
        map.put("data",workByWRId);
        return JSON.toJSONString(map);
    }
//    toolbar添加工序
    @RequestMapping(value="/addWork", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String addWork(workroutework_manytomany wwmtm){

        int i = iwrs.insertManytomany_WorkAndWorkRoute(wwmtm);
        if (i >= 1)
            return JSON.toJSONString("添加成功");
        else
            return JSON.toJSONString("添加失败");
    }
    // toolbar 修改工序
    @RequestMapping(value="/updateWork", produces = {"application/json;charset=utf-8", "text/plain;charset=utf-8"})
    public String updateWork(workVO wwmtm){

        int i = iwrs.updateManytomany_WorkAndWorkRoute(wwmtm);
        if (i >= 1)
            return JSON.toJSONString("修改成功");
        else
            return JSON.toJSONString("修改失败");
    }
}
